﻿using Localization.Shared;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;

namespace WebApi.Sample.Controllers;

[ApiController]
[Route("api/[controller]")]
public class ArticleController(IStringLocalizer<ArticleController> localizer) : ControllerBase
{
    [HttpGet("{id}")]
    public IActionResult GetArticle(int id)
    {
        var article = Data.GetArticles().FirstOrDefault(a => a.Id == id);
        if (article == null)
        {
            return NotFound();
        }
        var articleDto = new ArticleDto
        {
            Name = localizer[article.NameKey],
            Description = localizer[article.DescriptionKey]
        };
        return Ok(articleDto);
    }
}